#include "AlarmRank.h"
/*
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Security ip="10.10.108.129" date="1365580211000" digitalseal="9e0077aa79be0eedffecd4f5315d095d"/>
<Service business="AAS" function="getAlarmRankList"/>
<RequestInfo querytype="List" page="1" pagesize="">
<GetAlarmRank uid="root" token="4a2925d9a21219da053023b4d347f8c5" language="cn"/>
</RequestInfo>
</Request>

<?xml version="1.0" encoding="UTF-8"?>
<Result><ResultInfo resultcode="200" errormessage="OK"/>
<Service business="AAS" function="getAlarmRankList"/>
<ResultData querytype="List">
<AlarmRankList rank_id="3" rank_name="" rank_code="3" memo="DB.Alarm.RankMemo.GeneralAlarm"/>
<AlarmRankList rank_id="2" rank_name="" rank_code="2" memo="DB.Alarm.RankMemo.EmergencyAlarm"/>
<AlarmRankList rank_id="1" rank_name="" rank_code="1" memo="DB.Alarm.RankMemo.SeriousAlarm"/>
</ResultData>
</Result>
*/

AlarmRankReqReader::AlarmRankReqReader(void)
{
}


AlarmRankReqReader::~AlarmRankReqReader(void)
{
}

int AlarmRankReqReader::read(CommRequest& req)
{
	AlarmRankReq& alarmRankReq = static_cast<AlarmRankReq&>(req);
	TiXmlElement* pChild = m_pRootEle->FirstChildElement("RequestInfo");
	const char* strType = pChild->Attribute("querytype");
	TiXmlElement* pChild2 = pChild->FirstChildElement("GetAlarmRank");
	if (!pChild2)
		return -1;

	alarmRankReq.uid = pChild2->Attribute("uid");
	alarmRankReq.token = pChild2->Attribute("token");
	alarmRankReq.language = pChild2->Attribute("language");

	return 0;
}

AlarmRankRepWriter::AlarmRankRepWriter(void)
{
}


AlarmRankRepWriter::~AlarmRankRepWriter(void)
{
}
int AlarmRankRepWriter::doWrite(const CommReply& rep,string& reply)
{
	const AlarmRankRep& alarmRankRep = static_cast<const AlarmRankRep&>(rep);

	TiXmlElement ResultInfoEle("ResultInfo");
	ResultInfoEle.SetAttribute("resultcode",alarmRankRep.status);
	ResultInfoEle.SetAttribute("errormessage","OK");

	m_pRootNode->InsertEndChild(ResultInfoEle);

	TiXmlElement ServiceEle("Service");
	ServiceEle.SetAttribute("business","AAS");
	ServiceEle.SetAttribute("function","getAlarmRankList");
	m_pRootNode->InsertEndChild(ServiceEle);

	TiXmlElement ResultDataEle("ResultData");
	ResultDataEle.SetAttribute("querytype","list");

	TiXmlNode* pResultDataNode = m_pRootNode->InsertEndChild(ResultDataEle);

	int size = alarmRankRep.vecAlarmRank.size();
	for (int i=0;i<size;i++)
	{
		TiXmlElement orgEle("AlarmRankList");
		orgEle.SetAttribute("Rank_id",alarmRankRep.vecAlarmRank[i].id);
		orgEle.SetAttribute("Rank_name",alarmRankRep.vecAlarmRank[i].name);
		orgEle.SetAttribute("Rank_code",alarmRankRep.vecAlarmRank[i].code);

		TiXmlNode* pAuthNode = pResultDataNode->InsertEndChild(orgEle);
	}

	reply << *m_pDoc;

	return 0;
}